<template>
	<view>
		<u-navbar
			title="二维码"
			:autoBack="true"
			placeholder
		>
		</u-navbar>
		<scroll-view :scroll-y="true" :style="{height: scrollViewHeight, backgroundColor: appColor}">
			<view style="height: 36rpx;" />
			<view style="padding: 16rpx;height: 70%;overflow: hidden;">
				<view class="shop-top">
					<text>向工作人员展示二维码</text>
				</view>
				<view class="couponQrcode-box">
					<swiper
					  indicator-dots
					  :indicator-active-color="appColor"
					  circular
					  style="height: 100%;"
					>
						<swiper-item
						  v-for="(item, index) in list"
						  :key="index"
						>
							<view class="couponQrcode-box-1">
								<view style="margin-bottom: 16rpx;">{{item.couponName}} ({{Number(item.expiryDay) === 0 ? '长期有效' : `${item.endTime}到期`}})</view>
								<view style="width: 480rpx;height: 480rpx;position: relative;">
									<u--image mode="aspectFill" :src="item.qrCode" width="480rpx" height="480rpx"></u--image>
									<view v-if="item.status !== '0'" class="qr-mask">
										<text>{{item.status_dictText}}</text>
									</view>
								</view>
								<view style="padding-top: 16rpx;">核验码: {{item.code}}</view>
							</view>
						</swiper-item>
					</swiper>
					
				</view>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	import {mapState, mapActions} from 'vuex';
	import {couponQueryById} from '@/api/me.js';
	export default {
		data() {
			return {
				screenBrightness: 0,
				num: Date.now(),
				list: [],
				detail: {},
				timer: null,
			}
		},
		computed: {
			appColor() {
				return this.appPrimaryColor || '#f40215'
			},
			scrollViewHeight() {
				return this.scrollHeight - 44 + 'px';
			}
		},
		onLoad({id}) {
			let that = this;
			uni.getScreenBrightness({
				success(res) {
					that.screenBrightness = res.value;
					that.$cuLoading().then(() => {
						that.getData(id);
					})
					that.timer = setInterval(() => {
						that.getData(id);
					}, 3000)
				}
			})
		},
		methods: {
			getData(id) {
				let that = this;
				couponQueryById({id}).then(res => {
					this.list = [res.result];
					this.detail = res.result;
					uni.setScreenBrightness({
						value: 1
					})
				}).finally(() => {
					uni.hideLoading();
				})
			}
		},
		onUnload() {
			let that = this;
			uni.setScreenBrightness({
				value: that.screenBrightness
			})
			clearInterval(this.timer);
		}
	}
</script>

<style lang="scss" scoped>
	.shop-top {
		height: 100rpx;
		background-color: #F5F5F5;
		display: flex;
		align-items: center;
		color: #666;
		padding-left: 16rpx;
		border-radius: 4rpx 4rpx 0 0;
	}

	.couponQrcode-box {
		height: calc(100% - 100rpx);
		background-color: #fff;
		.couponQrcode-box-1 {
			height: 100%;
			display: flex;
			flex-direction: column;
			align-items: center;
			justify-content: center;
			border-radius: 0 0 4rpx 4rpx;
			.qr-mask {
				width: 480rpx;
				height: 480rpx;
				position: absolute;
				left: 0;
				top: 0;
				background-color: rgba(0,0,0,0.9);
				z-index: 10;
				text-align: center;
				line-height: 480rpx;
				color: #fff;
				font-size: 44rpx;
			}
		}
	}
</style>

